package com.gui.juc.base.safe;

import com.gui.utils.Sleeper;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.concurrent.Callable;

@Slf4j
public class BigDecimalDemo {

    public static void main(String[] args) {

        final BigDecimal[] bigDecimal = {new BigDecimal("10000")};

        for (int i = 0; i < 5; i++) {
            new Thread(() -> bigDecimal[0] = bigDecimal[0].subtract(new BigDecimal("1"))).start();
        }

        Sleeper.sleep(3);
        log.debug("最终的执行结果为：{}", bigDecimal[0]);

    }

    private static class Task implements Callable<BigDecimal> {

        private BigDecimal bigDecimal;

        public Task(BigDecimal bigDecimal) {
            this.bigDecimal = bigDecimal;
        }


        @Override
        public BigDecimal call() throws Exception {
            return bigDecimal.subtract(new BigDecimal("1"));
        }
    }
}
